<?php

namespace app\controller\admin\genshinteam;

use laytp\controller\Backend;
/**
 * Class Author
 * @package app\controller\admin\peace
 */
class Author extends Backend
{
    /**
     * api_log模型对象
     * @var \app\model\api\Log
     */
    protected $model;
    protected $hasSoftDel=0;//是否拥有软删除功能

    protected $noNeedLogin = []; // 无需登录即可请求的方法
    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法


    public function _initialize()
    {
        $this->model = new \app\model\api\GenshinAuthor();
    }


    public function index()
    {
        $special = $this->request->param("special","");
        if($special === "true"){
            $data = $this->model->order('id')->limit(0,2000)->select()->toArray();
            return $this->success('数据获取成功', $data);
        }
        $where   = $this->buildSearchParams();
        $order   = $this->buildOrder();
        $allData = $this->request->param('all_data');

        if ($allData) {
            $data = $this->model->where($where)->order($order)->cache(true)->select()->toArray();
        } else {
            $limit = $this->request->param('limit', 10);
            $data  = $this->model->where($where)->order($order)->paginate($limit)->toArray();
            foreach ($data['data'] as &$item){
                if(isset($item['url'])&&!empty($item['url'])){
                    $item['url'] = imgUrlToAbsolute($item['url']);
                }
                if(isset($item['icon'])&&!empty($item['icon'])){
                    $item['icon'] = imgUrlToAbsolute($item['icon']);
                }
            }
        }
        return $this->success('数据获取成功', $data);
    }

}